Lead Qualification with BatchData

工作流概述

这是一个包含17个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "0uon02fOzPkLcG6G",
  "meta": {
    "instanceId": "bb9853d4d7d87207561a30bc6fe4ece20b295264f7d27d4a62215de2f3846a56",
    "templateCredsSetupCompleted": true
  },
  "name": "Lead Qualification with BatchData",
  "tags": [],
  "nodes": [
    {
      "id": "376bc838-013e-4033-a508-d27a2a64d792",
      "name": "CRM New Lead Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2560,
        600
      ],
      "webhookId": "8fb37aae-df12-40eb-81ea-0e5022e1f988",
      "parameters": {
        "path": "crm-new-lead",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "2ca36d9f-7682-4a08-9fff-1674b36e07e4",
      "name": "Webhook Setup Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2720,
        160
      ],
      "parameters": {
        "color": 5,
        "width": 420,
        "height": 620,
        "content": "# WEBHOOK SETUP INSTRUCTIONS

1. Copy this webhook URL and configure your CRM to send notifications here
2. Expected payload format:
   ```
   {
     \"leadId\": \"123\",
     \"crmApiUrl\": \"https://your-crm-api.com/api/v1\",
     \"address\": \"123 Main St\",
     \"city\": \"Anytown\",
     \"state\": \"CA\",
     \"zipcode\": \"90210\"
   }
   ```
3. All fields are required for property verification"
      },
      "typeVersion": 1
    },
    {
      "id": "961b3c4c-5b58-439e-9c8c-cc6e9774ebe7",
      "name": "Fetch Lead Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2180,
        600
      ],
      "parameters": {
        "url": "={{ $json.crmApiUrl }}/leads/{{ $json.leadId }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.1
    },
    {
      "id": "3549918e-cea8-467e-90d0-3661a5f54ae9",
      "name": "CRM API Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2280,
        160
      ],
      "parameters": {
        "color": 5,
        "width": 300,
        "height": 620,
        "content": "# CRM API CONFIGURATION

1. Create HTTP Header Auth credentials for your CRM API
2. Include necessary authorization headers (e.g., 'Authorization: Bearer YOUR_TOKEN')
3. This node fetches comprehensive lead data using the lead ID from the webhook
4. Ensure your CRM API returns address information needed for property verification"
      },
      "typeVersion": 1
    },
    {
      "id": "25445c3c-adf0-41d7-8f5f-c0fabc297658",
      "name": "BatchData Property Lookup",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1840,
        600
      ],
      "parameters": {
        "url": "https://api.batchdata.com/api/v1/property/search",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "address",
              "value": "={{ $json.address }}"
            },
            {
              "name": "city",
              "value": "={{ $json.city }}"
            },
            {
              "name": "state",
              "value": "={{ $json.state }}"
            },
            {
              "name": "zipcode",
              "value": "={{ $json.zipcode }}"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.1
    },
    {
      "id": "85808ecf-e5b0-4d36-a2c3-66c26bb2a191",
      "name": "BatchData API Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1960,
        160
      ],
      "parameters": {
        "color": 5,
        "width": 360,
        "height": 620,
        "content": "# BATCHDATA API SETUP

1. Create an account at BatchData.com to get your API key
2. Set up HTTP Header Auth credentials with 'x-api-key: YOUR_BATCHDATA_API_KEY'
3. This API call verifies property details using the lead's address
4. Expected response includes property value, size, age, and ownership status
5. Adjust API endpoint if needed based on BatchData's documentation"
      },
      "typeVersion": 1
    },
    {
      "id": "389e2f49-9ed4-4017-8002-ac86e1001ed9",
      "name": "Score And Qualify Lead",
      "type": "n8n-nodes-base.code",
      "position": [
        -1480,
        620
      ],
      "parameters": {
        "jsCode": "// Initialize lead score
let score = 0;
let qualificationStatus = \"not qualified\";
let qualificationNotes = [];

// Get property data from BatchData response
const propertyData = $input.first().json;
const leadData = $input.first().json;

// Check if property exists
if (propertyData.success === true && propertyData.data) {
  const property = propertyData.data;
  
  // Score based on property value
  if (property.estimatedValue > 750000) {
    score += 30;
    qualificationNotes.push(\"High-value property: $\" + property.estimatedValue);
  } else if (property.estimatedValue > 500000) {
    score += 20;
    qualificationNotes.push(\"Mid-high value property: $\" + property.estimatedValue);
  } else if (property.estimatedValue > 350000) {
    score += 10;
    qualificationNotes.push(\"Average value property: $\" + property.estimatedValue);
  }
  
  // Score based on property size
  if (property.squareFootage > 3000) {
    score += 15;
    qualificationNotes.push(\"Large property: \" + property.squareFootage + \" sq ft\");
  } else if (property.squareFootage > 2000) {
    score += 10;
    qualificationNotes.push(\"Mid-size property: \" + property.squareFootage + \" sq ft\");
  }
  
  // Score based on property age
  const currentYear = new Date().getFullYear();
  const propertyAge = currentYear - property.yearBuilt;
  
  if (propertyAge < 5) {
    score += 15;
    qualificationNotes.push(\"New construction: \" + property.yearBuilt);
  } else if (propertyAge < 20) {
    score += 10;
    qualificationNotes.push(\"Relatively new property: \" + property.yearBuilt);
  }
  
  // Other factors to consider
  if (property.ownerOccupied === false) {
    score += 15;
    qualificationNotes.push(\"Investment property (not owner-occupied)\");
  }
  
  if (property.lotSize > 0.5) {
    score += 10;
    qualificationNotes.push(\"Large lot size: \" + property.lotSize + \" acres\");
  }
  
  // Determine qualification status based on score
  if (score >= 50) {
    qualificationStatus = \"high-value\";
  } else if (score >= 30) {
    qualificationStatus = \"qualified\";
  } else if (score >= 15) {
    qualificationStatus = \"potential\";
  }
  
  // Combine all data for CRM update
  const enrichedData = {
    leadId: leadData.leadId,
    score: score,
    qualificationStatus: qualificationStatus,
    qualificationNotes: qualificationNotes.join(\", \"),
    propertyData: {
      estimatedValue: property.estimatedValue,
      squareFootage: property.squareFootage,
      yearBuilt: property.yearBuilt,
      lotSize: property.lotSize,
      bedrooms: property.bedrooms,
      bathrooms: property.bathrooms,
      ownerOccupied: property.ownerOccupied,
      lastSaleDate: property.lastSaleDate,
      lastSalePrice: property.lastSalePrice
    }
  };
  
  return enrichedData;
} else {
  // If property data not found
  qualificationNotes.push(\"Property data not found or verification failed\");
  
  return {
    leadId: leadData.leadId,
    score: 0,
    qualificationStatus: \"unverified\",
    qualificationNotes: qualificationNotes.join(\", \"),
    propertyData: null
  };
}"
      },
      "typeVersion": 2
    },
    {
      "id": "f33f6442-5e8b-4aab-b5ff-d37d062a5cfa",
      "name": "Lead Scoring Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1580,
        -280
      ],
      "parameters": {
        "color": 3,
        "width": 320,
        "height": 1060,
        "content": "# LEAD SCORING ALGORITHM

This function implements a sophisticated scoring system for property-based leads:

### SCORING FACTORS
- **Property Value**
  - >$750k: 30 points
  - >$500k: 20 points
  - >$350k: 10 points

- **Square Footage**
  - >3000 sq ft: 15 points
  - >2000 sq ft: 10 points

- **Property Age**
  - <5 years old: 15 points
  - <20 years old: 10 points

- **Other Factors**
  - Investment property: 15 points
  - Large lot (>0.5 acres): 10 points

### QUALIFICATION THRESHOLDS
- **High-value**: 50+ points
- **Qualified**: 30-49 points
- **Potential**: 15-29 points
- **Not qualified**: <15 points
- **Unverified**: No property data

Customize the scoring values and thresholds to match your specific business requirements."
      },
      "typeVersion": 1
    },
    {
      "id": "b9bcb2af-6ccc-4f9e-9926-765df4f36809",
      "name": "Update CRM Lead",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1120,
        620
      ],
      "parameters": {
        "url": "={{ $json.crmApiUrl }}/leads/{{ $json.leadId }}",
        "method": "PUT",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "score",
              "value": "={{ $json.score }}"
            },
            {
              "name": "qualificationStatus",
              "value": "={{ $json.qualificationStatus }}"
            },
            {
              "name": "qualificationNotes",
              "value": "={{ $json.qualificationNotes }}"
            },
            {
              "name": "propertyValue",
              "value": "={{ $json.propertyData.estimatedValue }}"
            },
            {
              "name": "squareFootage",
              "value": "={{ $json.propertyData.squareFootage }}"
            },
            {
              "name": "yearBuilt",
              "value": "={{ $json.propertyData.yearBuilt }}"
            },
            {
              "name": "bedrooms",
              "value": "={{ $json.propertyData.bedrooms }}"
            },
            {
              "name": "bathrooms",
              "value": "={{ $json.propertyData.bathrooms }}"
            },
            {
              "name": "batchDataVerified",
              "value": "={{ $json.propertyData !== null }}"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.1
    },
    {
      "id": "3cfa64f8-527a-49d5-9787-156fe084f37c",
      "name": "CRM Update Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1240,
        160
      ],
      "parameters": {
        "color": 5,
        "width": 340,
        "height": 620,
        "content": "# CRM UPDATE CONFIGURATION

1. This node updates your CRM with enriched property data and lead qualification information
2. Adjust field names in the body parameters to match your CRM's API schema
3. Common fields to update include:
   - Lead score and qualification status
   - Property details (value, size, beds/baths)
   - Verification status
4. If your CRM uses PATCH instead of PUT, adjust the method accordingly
5. Make sure your CRM credentials have write access to update lead records"
      },
      "typeVersion": 1
    },
    {
      "id": "8470bcf6-a539-4f75-8494-f76bcfc95f00",
      "name": "Is High-Value Lead?",
      "type": "n8n-nodes-base.if",
      "position": [
        -760,
        620
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.qualificationStatus }}",
              "value2": "high-value"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "da84ac21-fbb2-4640-8e92-f40b23d2fa0a",
      "name": "Routing Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        160
      ],
      "parameters": {
        "color": 3,
        "width": 320,
        "height": 620,
        "content": "# ROUTING LOGIC

This conditional node determines the workflow path based on the lead's qualification:

- **TRUE Path (Top)**: Routes high-value leads for immediate follow-up
- **FALSE Path (Bottom)**: Routes standard leads for notification only

You can modify the condition to create different paths based on:
- Score thresholds (e.g., >30 points)
- Property characteristics (e.g., property value >$1M)
- Geographic targeting (e.g., specific ZIP codes)
- Lead source (e.g., referrals vs. web leads)"
      },
      "typeVersion": 1
    },
    {
      "id": "c7772695-cda1-4483-a961-7468fd075c55",
      "name": "Create Immediate Follow-up Task",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -180,
        320
      ],
      "parameters": {
        "url": "={{ $json.crmApiUrl }}/tasks",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "type",
              "value": "immediate-followup"
            },
            {
              "name": "leadId",
              "value": "={{ $json.leadId }}"
            },
            {
              "name": "priority",
              "value": "high"
            },
            {
              "name": "dueDate",
              "value": "={{ $now.format(\"YYYY-MM-DD\") }}"
            },
            {
              "name": "note",
              "value": "High-value lead with property value of ${{ $json.propertyData.estimatedValue }}. Immediate follow-up required."
            },
            {
              "name": "assignedTo",
              "value": "senior-agent"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.1
    },
    {
      "id": "2fd15500-7314-4910-b822-c3d9de4166df",
      "name": "Follow-up Task Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        -140
      ],
      "parameters": {
        "color": 4,
        "width": 420,
        "height": 640,
        "content": "# HIGH-VALUE LEAD HANDLING

1. This node creates an urgent follow-up task for premium leads
2. Customize parameters to match your CRM/task system's API:
   - Assignee (currently \"senior-agent\")
   - Priority level and task type
   - Due date format
   - Task description
3. Alternative approaches:
   - Send email alerts to sales managers
   - Create Salesforce opportunities
   - Trigger SMS notifications
   - Add to special follow-up campaign"
      },
      "typeVersion": 1
    },
    {
      "id": "0d0d4e2e-b040-45d1-8a4c-e775520a4bbc",
      "name": "Send Slack Notification",
      "type": "n8n-nodes-base.slack",
      "position": [
        -60,
        860
      ],
      "webhookId": "dc308b09-6aea-41be-96c4-c322cfc8ed8f",
      "parameters": {
        "text": "=High-value lead alert: {{ $json.leadId }}
Property Value: ${{ $json.propertyData.estimatedValue }}
Score: {{ $json.score }}
Qualification Notes: {{ $json.qualificationNotes }}",
        "select": "channel",
        "channelId": "high-value-leads",
        "otherOptions": {}
      },
      "typeVersion": 2
    },
    {
      "id": "de158d72-7472-4075-ba57-13916739d24b",
      "name": "Notification Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        520
      ],
      "parameters": {
        "color": 4,
        "width": 460,
        "height": 500,
        "content": "# NOTIFICATION CONFIGURATION

1. Set up Slack credentials in n8n's Credentials Manager
2. Update the channel ID to match your Slack workspace
3. Customize the notification format and content
4. Alternative options:
   - Replace with Email notification
   - Use Microsoft Teams
   - Send SMS alerts via Twilio
   - Post to a dedicated dashboard
   - Log to monitoring system"
      },
      "typeVersion": 1
    },
    {
      "id": "1433b56d-3d8e-465a-bccc-c2dece4d6a1c",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3200,
        260
      ],
      "parameters": {
        "width": 400,
        "height": 400,
        "content": "# BatchData Lead Qualification Workflow

This workflow integrates with BatchData's Property Lookup API to verify, enrich, and qualify leads based on property data. When a new lead is added to your CRM, the workflow:

1. Retrieves the lead's address information
2. Verifies property details using BatchData's API
3. Scores and qualifies the lead based on property characteristics
4. Updates the CRM with enriched data and qualification status
5. Routes high-value leads for immediate follow-up

## SETUP CHECKLIST
- [ ] Configure CRM API credentials
- [ ] Set up BatchData API key
- [ ] Configure Slack/notification credentials
- [ ] Customize scoring thresholds
- [ ] Adjust CRM field mappings
- [ ] Test with sample lead data"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d914c2d9-b2af-4c00-b5cd-7ed80d713cb0",
  "connections": {
    "Fetch Lead Data": {
      "main": [
        [
          {
            "node": "BatchData Property Lookup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update CRM Lead": {
      "main": [
        [
          {
            "node": "Is High-Value Lead?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is High-Value Lead?": {
      "main": [
        [
          {
            "node": "Create Immediate Follow-up Task",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Slack Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM New Lead Webhook": {
      "main": [
        [
          {
            "node": "Fetch Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score And Qualify Lead": {
      "main": [
        [
          {
            "node": "Update CRM Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "BatchData Property Lookup": {
      "main": [
        [
          {
            "node": "Score And Qualify Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Webhook
  • Stickynote
  • Httprequest
  • Code
  • If

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作